package com.bjsxt.controller;

import com.bjsxt.domain.SysMenu;
import com.bjsxt.model.R;
import com.bjsxt.model.RolePrivilegesParam;
import com.bjsxt.service.SysRolePrivilegeService;
import com.bjsxt.service.SysRolePrivilegeUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "角色权限的配置")
@RestController
public class SysRolePrivilegeController {

    @Autowired
      SysRolePrivilegeService sysRolePrivilegeService;


    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色id")
    })
    public R<List<SysMenu>>  findSysMenuAndPrivileges(Long roleId){

        List<SysMenu> sysMenus  = sysRolePrivilegeService.findSysMenuAndPrivileges(roleId) ;
        System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        System.out.println(sysMenus);
        return R.ok(sysMenus) ;

    }



    @PostMapping("/grant_privileges")
    @ApiOperation(value = "授予角色权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rolePrivilegesParam",value = "rolePrivilegesParam json 数据  角色id 权限列表")
    })
    public R grantPrivileges(@RequestBody RolePrivilegesParam rolePrivilegesParam){
    boolean isOk = sysRolePrivilegeService.grantPrivileges(rolePrivilegesParam);
    if(isOk){
        return R.ok();
    }
    return R.fail("授予失败");

    }


}
